package model;

import java.io.Serializable;

/**
 * This class implements the actual cards of the game.
 * Each card has a number value and a suit value
 */

public class Card implements Serializable {
	/**
	 * The card rank is the face value of the card
	 * It includes a numerical value of the card for
	 * ranking purposes
	 */
	public enum CardRankEnum implements Serializable {
		DEUCE(2), THREE(3), FOUR(4), FIVE(5), SIX(6), SEVEN(7), EIGHT(8), NINE(9), TEN(10), JACK(11), QUEEN(12), KING(13), ACE(14);
	
		private int rankValue;
		
		CardRankEnum(int rankValue) {
			this.rankValue = rankValue;
		}
		
		public int getValue(){
			return rankValue;
		}
	}
	
	/**
	* The card suit is the suit value of the card
	 * It includes a numerical value of the suit for
	 * ranking purposes
	 */
	public enum CardSuitEnum implements Serializable {
		DIAMONDS(1), CLUBS(2), HEARTS(3), SPADES(4);
		
		private int suitValue;
		CardSuitEnum(int suitValue) {
			this.suitValue = suitValue;
		}
		
		public int getValue() {
			return suitValue;
		}
	}
	
	private CardRankEnum rank;
	private CardSuitEnum suit;
	private boolean faceUp;
	private int intRepresentation;
	
	/**
	 * Constructor, sets the rank and suit of the card
	 * The card is created as a faceUp card by default
	 * The intRepresentation of the card is 10 times the
	 * rank value plus the value of the suit, as is common
	 * in most poker games 
	 */
	public Card(CardRankEnum rank, CardSuitEnum suit) {
		this.rank = rank;
		this.suit = suit;
		this.faceUp = true;
		intRepresentation = 10*rank.getValue() + suit.getValue();
	}

	//Getters and setters:
	
	public int asInt() {
		return intRepresentation;
	}
	
	public void setFaceUp(boolean faceUp) {
		this.faceUp = faceUp;
	}
	
	public boolean isFaceUp() {
		return faceUp;
	}

	public CardRankEnum getRank() {
		return rank;
	}
	
	public int getCardValue(){
		return rank.getValue();
	}
	
	public CardSuitEnum getSuit() {
		return suit;
	}

	@Override
	public String toString() {
		return "Card [rank="+rank+", suit="+suit+", faceUp="+faceUp+"]";
	}
}
